#include <mFS/FsTypes.h>
#include <mFS/mConfig.h>
#include <mHAL/hal/Hal.h>
#include <mFS/mFS.h>
#include <Utils/IdDef.h>
#include <Utils/StructDef.h>
#include <Utils/Mem.h>
#include "CommonAP.h"
#include "SessionCAP.h"

#include "SwCode.h"

#include "CryptSessionAP.h"


UINT16 CryptSessionAP_DestroySessionKey(UINT8 *pInBuf)
{
	UINT16 AppId, ContainerId, KeyId;
	UINT16 nRet;

	Mem_CopyBytes(&AppId, pInBuf, sizeof(UINT16));pInBuf += sizeof(UINT16);
	Mem_CopyBytes(&ContainerId, pInBuf, sizeof(UINT16));pInBuf += sizeof(UINT16);
	Mem_CopyBytes(&KeyId, pInBuf, sizeof(UINT16));

	Mem_ConvertEndian(&AppId, sizeof(UINT16), MEM_HOST_BIG_ENDIAN);
	Mem_ConvertEndian(&ContainerId, sizeof(UINT16), MEM_HOST_BIG_ENDIAN);
	Mem_ConvertEndian(&KeyId, sizeof(UINT16), MEM_HOST_BIG_ENDIAN);

	nRet = CommonAP_InsertIntoContainer(AppId, ContainerId, 0, FALSE, 0);
	if(nRet != ISOSW_SUCCESSFUL)
	{
		return (nRet);
	}

	nRet = SessionCAP_Destroy(AppId, ContainerId, KeyId);

	return (nRet);
}
